package org.dromara.system.service.impl;

import org.dromara.system.service.SysOperateLogService;
import org.dromara.system.pojo.entity.SysOperateLogDO;
import org.dromara.system.pojo.bo.SysOperateLogBO;
import org.dromara.system.pojo.qo.SysOperateLogQO;
import org.dromara.system.pojo.vo.SysOperateLogVO;
import org.dromara.system.mapper.SysOperateLogMapper;
import org.springframework.stereotype.Service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;

import java.util.List;

/**
 * 操作日志记录 服务层实现。
 *
  * @author mkj
  * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysOperateLogServiceImpl  implements SysOperateLogService {

    private final SysOperateLogMapper sysOperateLogMapper;

    @Override
    public boolean add(SysOperateLogBO sysOperateLogBO) {
        SysOperateLogDO sysOperateLogDO = BeanCopyUtils.copy(sysOperateLogBO, SysOperateLogDO.class);
        return sysOperateLogMapper.insert(sysOperateLogDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysOperateLogMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysOperateLogBO sysOperateLogBO) {
        SysOperateLogDO sysOperateLogDO = BeanCopyUtils.copy(sysOperateLogBO, SysOperateLogDO.class);
        return sysOperateLogMapper.update(sysOperateLogDO) > 0;
    }

    @Override
    public List<SysOperateLogVO> list(SysOperateLogQO sysOperateLogQO) {
        SysOperateLogDO sysOperateLogDO = BeanCopyUtils.copy(sysOperateLogQO, SysOperateLogDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysOperateLogDO);
        return sysOperateLogMapper.selectListByQueryAs(queryWrapper, SysOperateLogVO.class);
    }

    @Override
    public SysOperateLogVO getInfo(@PathVariable Long id) {
        SysOperateLogDO sysOperateLogDO = sysOperateLogMapper.selectOneById(id);
        if (sysOperateLogDO == null){
            return null;
        }
        return BeanCopyUtils.copy(sysOperateLogDO, SysOperateLogVO.class);
    }

    @Override
    public Page<SysOperateLogVO> page(SysOperateLogQO page) {
        return sysOperateLogMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysOperateLogVO.class);
    }

}

